package org.ytor.core.sysapi.user.repository;

import org.ytor.core.sqlflow.BaseRepository;
import org.ytor.core.sqlflow.SQLHelper;
import org.ytor.core.sysapi.depart.model.SysDepart;
import org.ytor.core.sysapi.depart.resp.SysDepartResp;
import org.ytor.core.sysapi.user.model.SysUserDepart;

import java.util.List;

/**
 * created by   on 2025年4月9日 23:03:21
 * <br/>
 * User表Mapper
 * <br/>
 */
public class SysUserDepartRepository extends BaseRepository<SysUserDepart> {

    /**
     * 根据userId数组查询指定用户的部门信息
     */
    public List<SysDepartResp> queryDepartByUserIds(List<String> userIds) {
        return SQLHelper.select()
                .from(SysUserDepart.class)
                .leftJoin(SysDepart.class, on -> on.eq(SysUserDepart::getId, SysDepart::getId))
                .where(w -> w.in(SysUserDepart::getUserId, userIds))
                .list(SysDepartResp.class);
    }
}